


cc.Class({
    extends: cc.Component,

    properties: {
        rankIcon: cc.Sprite,
        head_sp: cc.Sprite,
        title_lab: cc.Label,
        shiwan_node: cc.Node,
        rankLab: cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },

    // update (dt) {},

    init(info, index) {
        if (info) {
            this.loadImg(this.head_sp, info.show_config.image)
            this.title_lab.string = info.show_config.title
            this.crtId = info.creativeId
            this.posId = info.positionId
        }
        this.rankLab.node.active = false
        this.shiwan_node.active = true
        if (index == 0) {
            this.rankIcon.spriteFrame = he.load.get('fakeRank', cc.SpriteAtlas, 'plist').getSpriteFrame('first')
        } else if (index == 1) {
            this.rankIcon.spriteFrame = he.load.get('fakeRank', cc.SpriteAtlas, 'plist').getSpriteFrame('second')
        } else if (index == 2) {
            this.rankIcon.spriteFrame = he.load.get('fakeRank', cc.SpriteAtlas, 'plist').getSpriteFrame('third')
        } else {
            // this.shiwan_node.active=false
            this.rankLab.node.active = true
            this.rankIcon.node.active = false
            this.rankLab.string = `${index + 1}`
        }

        this.isCanClick = true
    },


    loadImg(container, url) {
        cc.assetManager.loadRemote(url, { ext: '.png' }, function (err, texture) {
            if (err) {
                console.error(err)
            }
            var sprite = new cc.SpriteFrame(texture);
            container.spriteFrame = sprite;
        });
    },

    clilkServer() {
        if (wx.tmSDK && this.isCanClick) {
            this.isCanClick = false
            wx.tmSDK.flowNavigate({
                positionId: this.posId, // 广告位id, 请先使用该id获取推广创意列表
                creativeId: +this.crtId,  // 传入获取到的creativeId
            }).then((newList) => {
                // console.log('跳转成功or取消跳转（可根据特有返回值区分两种情况）')
                // console.log('自动刷新列表：', newList)//返回最新列表 
                this.isCanClick = true
            }).catch((error) => {
                // console.log('跳转失败', error);
                this.isCanClick = true
            })
        }
    },
});
